# -*- coding: utf-8 -*-
# !/usr/bin/env python
# -*- coding: utf-8 -*-

import time

ft = open("temp", 'r')
fh = open("sorted_temp", 'w')
lines = ft.readlines()
lineNum = len(lines)
for i in range(lineNum):
    for j in range(lineNum - 1, i, -1):
        iStrtime, jStrtime = lines[i].split('\t')[0].strip(), lines[j].split('\t')[0].strip()
        iCtime, jCtime = time.strptime(iStrtime,"%b %d %H:%M:%S %Y"), time.strptime(jStrtime,"%b %d %H:%M:%S %Y")
        if iCtime > jCtime:
            lines[i], lines[j]=lines[j], lines[i]
fh.writelines(lines)
ft.close()
fh.close()
